| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var chai = require('chai'); |
||
| 4 | describe("Helpers", function () { |
||
| 5 | describe("lowercase", function () { |
||
| 6 | it('properly lowercase string', function() { |
||
| 7 | var value = 'ThiS IS mY String', |
||
| 8 | rendered = Handlebars.helpers.lowercase(value), |
||
| 9 | expected = 'this is my string'; |
||
| 10 | chai.expect(rendered).to.eql(expected); |
||
| 11 | }); |
||
| 12 | it('properly return empty string', function() { |
||
| 13 | var value = null, |
||
| 14 | rendered = Handlebars.helpers.lowercase(value), |
||
| 15 | expected = ''; |
||
| 16 | chai.expect(rendered).to.eql(expected); |
||
| 17 | }); |
||
| 18 | }); |
||
| 19 | describe("uppercase", function () { |
||
| 20 | it('properly uppercase string', function() { |
||
| 21 | var value = 'ThiS IS mY String', |
||
| 22 | rendered = Handlebars.helpers.uppercase(value), |
||
| 23 | expected = 'THIS IS MY STRING'; |
||
| 24 | chai.expect(rendered).to.eql(expected); |
||
| 25 | }); |
||
| 26 | it('properly return empty string', function() { |
||
| 27 | var value = null, |
||
| 28 | rendered = Handlebars.helpers.uppercase(value), |
||
| 29 | expected = ''; |
||
| 30 | chai.expect(rendered).to.eql(expected); |
||
| 31 | }); |
||
| 32 | }); |
||
| 33 | describe("truncate", function () { |
||
| 34 | it('properly truncate string', function() { |
||
| 35 | var value = 'ThiS IS mY String', |
||
| 36 | length = 10, |
||
| 37 | rendered = Handlebars.helpers.truncate(value, length), |
||
| 38 | expected = 'ThiS IS mY...'; |
||
| 39 | chai.expect(rendered).to.eql(expected); |
||
| 40 | }); |
||
| 41 | it('properly return full string', function() { |
||
| 42 | var value = 'ThiS IS mY String', |
||
| 43 | length = 20, |
||
| 44 | rendered = Handlebars.helpers.truncate(value, length), |
||
| 45 | expected = 'ThiS IS mY String'; |
||
| 46 | chai.expect(rendered).to.eql(expected); |
||
| 47 | }); |
||
| 48 | it('properly return empty string', function() { |
||
| 49 | var value = null, |
||
| 50 | length = 10, |
||
| 51 | rendered = Handlebars.helpers.truncate(value, length), |
||
| 52 | expected = ''; |
||
| 53 | chai.expect(rendered).to.eql(expected); |
||
| 54 | }); |
||
| 55 | }); |
||
| 56 | }); |